enum UNIT {
    //% block="Temperature(℃)"
    getTemperature_C,
    //% block="Temperature(℉)"
    getTemperature_F,
    //% block="Humidity(%RH)"
    getHumidity_RH
}

enum I2C_ADD {
    //% block="0x38"
    0x38
}

//% color="#3676b8" iconWidth=50 iconHeight=40
namespace aht20{
    //% block="AHT20 module initialization I2C address[I2C_ADD]" blockType="command"
    //% I2C_ADD.shadow="dropdown"   I2C_ADD.options="I2C_ADD"
    export function init(parameter: any, block: any) { 
        let i2c_add = parameter.I2C_ADD.code;
        Generator.addInclude("DFRobot_AHT20", `#include "DFRobot_AHT20.h"`);
        Generator.addObject(`object`, `DFRobot_AHT20 `, `aht20;`);  
        //Generator.addSetup(`DFRobot_aht20InitReady`,`while(aht20.begin()!= 0){delay(1000);}`);
   } 

    //% block="IsStartMeasurementReady" blockType="boolean"
    export function isStartMeasurementReady(parameter: any, block: any) { 
        Generator.addCode(`aht20.startMeasurementReady()`);
   } 

    //% block="read AHT20 sensor[UNIT]" blockType="reporter"
    //% UNIT.shadow="dropdown"   UNIT.options="UNIT"
    export function getValueDate(parameter: any, block: any) { 
        let unit = parameter.UNIT.code;
        Generator.addCode(`aht20.${unit}()`);
   } 
}